//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"

struct PD{
    int pl;
    std::string sub;
};
bool cmp(PD& pd1,PD&pd2){
    if(pd1.pl>pd2.pl){
        return true;
    }else if(pd1.pl<pd2.pl){
        return false;
    }else{
        if(pd1.sub.size()==pd2.sub.size()){
            return pd1.sub<pd2.sub;
        }
        return pd1.sub.size()<pd2.sub.size();
    }
}
//一个升序，一个降序
struct Sol{
    std::unordered_map<std::string,int> set_to_pl;
    std::vector<PD> vec;
    void handle(int a,int b,int n){
        std::string str;
        std::getline(std::cin,str);
        std::getline(std::cin,str);
        b= std::min(b,(int)str.size());
        for(int len=a;len<=b;len++){
            for (int off = 0; off <=str.size()-len; ++off) {
                std::string sub=str.substr(off,len);
                if(sub=="0"){
                    printf("");
                }
                if(set_to_pl.find(sub)==set_to_pl.end()){
                    set_to_pl[sub]=1;
                }else{
                    set_to_pl[sub]++;
                }
            }
        }
        for(auto&pair:set_to_pl){
            vec.push_back({pair.second,pair.first});
        }
        std::sort(vec.begin(),vec.end(),cmp);

        int i=0;

        int vec_i=0;
        bool first= true;
        while(1){
            if(vec_i>=vec.size()){
                break;
            }
            if(vec_i==0||vec[vec_i].pl!=vec[vec_i-1].pl){
                i++;
                if(i==n+1){
                    break;
                }
                if(vec_i!=0){
                    printf("\n");
                }
                printf("%d\n",vec[vec_i].pl);
                first= true;
            }
            if(!first){
                printf(" ");
            }
            first= false;
            std::cout<<vec[vec_i].sub;
            vec_i++;
        }
        ;
    }
};
int main(){
    int a,b,c;
    while(std::cin>>a>>b>>c){
            Sol().handle(a,b,c);

    }

    return 0;
}